package com.core.zyyz.pcmc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.core.zyyz.pcmc.domain.PcmcDataPermissionRule;
import com.core.zyyz.pcmc.service.PcmcDataPermissionRuleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.common.utils.poi.ExcelUtil;
import com.core.common.core.page.TableDataInfo;

/**
 * 数据权限规则Controller
 *
 * @author core
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/pcmc/datePermissionRule")
public class PcmcDataPermissionRuleController extends BaseController
{
    @Autowired
    private PcmcDataPermissionRuleService pcmcDataPermissionRuleService;

    /**
     * 查询数据权限规则列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:datePermissionRule:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcmcDataPermissionRule pcmcDataPermissionRule)
    {
        startPage();
        List<PcmcDataPermissionRule> list = pcmcDataPermissionRuleService.selectPcmcDataPermissionRuleList(pcmcDataPermissionRule);
        return getDataTable(list);
    }

    /**
     * 导出数据权限规则列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:datePermissionRule:export')")
    @Log(title = "数据权限规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcmcDataPermissionRule pcmcDataPermissionRule)
    {
        List<PcmcDataPermissionRule> list = pcmcDataPermissionRuleService.selectPcmcDataPermissionRuleList(pcmcDataPermissionRule);
        ExcelUtil<PcmcDataPermissionRule> util = new ExcelUtil<PcmcDataPermissionRule>(PcmcDataPermissionRule.class);
        util.exportExcel(response, list, "数据权限规则数据");
    }

    /**
     * 获取数据权限规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcmc:datePermissionRule:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(pcmcDataPermissionRuleService.selectPcmcDataPermissionRuleByRuleId(ruleId));
    }

    /**
     * 新增数据权限规则
     */
    @PreAuthorize("@ss.hasPermi('pcmc:datePermissionRule:add')")
    @Log(title = "数据权限规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcmcDataPermissionRule pcmcDataPermissionRule)
    {
        return toAjax(pcmcDataPermissionRuleService.insertPcmcDataPermissionRule(pcmcDataPermissionRule));
    }

    /**
     * 修改数据权限规则
     */
    @PreAuthorize("@ss.hasPermi('pcmc:datePermissionRule:edit')")
    @Log(title = "数据权限规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcmcDataPermissionRule pcmcDataPermissionRule)
    {
        return toAjax(pcmcDataPermissionRuleService.updatePcmcDataPermissionRule(pcmcDataPermissionRule));
    }

    /**
     * 删除数据权限规则
     */
    @PreAuthorize("@ss.hasPermi('pcmc:datePermissionRule:remove')")
    @Log(title = "数据权限规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(pcmcDataPermissionRuleService.deletePcmcDataPermissionRuleByRuleIds(ruleIds));
    }
}
